<?php
/**
 * Script para las acciones del admin de comentarios
 * @author Sahib J. Leo
 */
require '../../config.php';
require PATH . 'classes/ofj-orm/Comentario.php';

$Response = (object)array(
  'error'    => false,
  'messsage' => ''
);

switch($_GET['action']){
  case 'approve':
    try {
      Comentario::instance()->update(array(
        'estado' => 'A'
      ), array(
        'where'     => '`id`=:id',
        'arguments' => array(':id' => (int)$_POST['comment_id'])
      ));
    } catch (SahORMException $e) {
      $Response->error = true;
      $Response->message = 'No se pudo borrar el comentario';
    }
    break;
  case 'delete':
    try {
      Comentario::instance()->delete(array(
        'where'     => '`id`=:id',
        'arguments' => array(':id' => (int)$_POST['comment_id'])
      ));
    } catch (SahORMException $e) {
      $Response->error = true;
      $Response->message = 'No se pudo borrar el comentario'; 
    }
    break;
}

header('Content-Type:application/json;charset=utf-8');
echo json_encode($Response);
?>